import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_fun_zjversion/ui/page/splash.dart';
import 'package:flutter_fun_zjversion/view_model/local_model.dart';
import 'package:flutter_fun_zjversion/view_model/theme_model.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';

import 'config/provider_manager.dart';
import 'config/router_config.dart';
import 'config/storage_manager.dart';
import 'config/ui_adapter_config.dart';
import 'package:oktoast/oktoast.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'generated/i18n.dart';

void main() async {
  Provider.debugCheckInvalidValueType = null;

  /// 全局屏幕适配方案
//  InnerWidgetsFlutterBinding.ensureInitialized()
//    ..attachRootWidget(App(future: StorageManager.init()))
//    ..scheduleWarmUpFrame();

  Provider.debugCheckInvalidValueType = null;
  WidgetsFlutterBinding.ensureInitialized();
  await StorageManager.init();
  runApp(App());
  // Android状态栏透明
  SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(statusBarColor: Colors.transparent));
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OKToast(
        child: MultiProvider(
            providers: providers,
            child: Consumer2<ThemeModel, LocaleModel>(
                builder: (context, themeModel, localeModel, child) {
                  return RefreshConfiguration(
                    hideFooterWhenNotFull: true, //列表数据不满一页,不触发加载更多
                    child: MaterialApp(
                      debugShowCheckedModeBanner: false,
                      theme: themeModel.themeData,
                      darkTheme: themeModel.darkTheme,
                      locale: localeModel.locale,
                      localizationsDelegates: const [
                        S.delegate,
                        GlobalCupertinoLocalizations.delegate,
                        GlobalMaterialLocalizations.delegate,
                        GlobalWidgetsLocalizations.delegate
                      ],
                      supportedLocales: S.delegate.supportedLocales,
                      onGenerateRoute: Router.generateRoute,
                      initialRoute: RouteName.splash,
                    ),
                  );
                })));
  }
}
